<template>
  <div class="header">
    <!-- <div class="title">空域资源综合管理</div> -->
    <div class="title">实时空域运行管控系统</div>
    <div class="header-content">
      <div class="time">
        <span v-for="(_, index) in time" :key="index">
          {{ time[index] }} <span v-if="index < 2">:</span></span>
      </div>
      <div class="right">
        <div class="user-info">{{ userName }}</div>
        <!-- <div class="setup custom-icon"></div> -->
        <div class="back_home custom-icon" @click="goBackHome"></div>
        <div class="logout custom-icon" @click="logout"></div>
      </div>
    </div>
  </div>
</template>

<script>
import store from "@/store";
const baseApi = process.env.NODE_ENV === 'production'
  //? process.env.VUE_APP_REMOTE_API
  ? '/api'  // 使用代理路径
  : process.env.VUE_APP_REMOTE_API_MODULE2;

export default {
  name: "Header",
  data() {
    return {
      time: null,
      timer: null,
      // userName: store.getters.name,
      // userName: this.$store.state.user.name,
    };
  },
  computed: {
    userName() {
      return this.$store.state.user.name;
    }
  },
  methods: {
    goBackHome() {
      // this.$router.push("/homePage")
      // if (window.history.length > 1) {
      //   this.$router.go(-1);
      // } else {
      //   console.log("没有上一个页面，保持不动");
      // }
      // window.location.href = "http://110.41.17.45:9015/unmannedControl/serviceAccess";
      window.location.href = process.env.VUE_APP_JUMP_BACK;
    },
    logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          // 成功退出后跳转到运管中心的登录界面
          console.log("成功退出后跳转到运管中心的登录界面")
          // const loginUrl = process.env.VUE_APP_JUMP_API
          // window.location.href = loginUrl
        }).catch(() => {
          this.$message.error('退出失败，请重试');
        });
      }).catch(() => {
        // 用户取消了退出操作
      });
    }
  },
  beforeMount() {
    this.timer = null;
    this.timer = setInterval(() => {
      this.time = this.parseTime(new Date(), "{h}-{i}-{s}-{y}-{m}-{d}").split("-");
    }, 1000);
  },
  beforeDestroy() {
    this.timer = null;
  },
};
</script>

<style lang="scss" scoped>
@import "../scss/index";
</style>
